package yt.demo.appcommondb.base;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.Date;

@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
public abstract class BaseEntity<T extends Model<T>> extends Model<T> {

    public interface CreateGroup {}

    public interface UpdateGroup {}

    @TableField(fill = FieldFill.INSERT, value = "created_at")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    @JsonProperty("created_at")
    @Schema(name = "createdAt", description = "创建时间")
    private Date createTime;

    @TableField(fill = FieldFill.INSERT_UPDATE, value = "updated_at")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    @JsonProperty("updated_at")
    @Schema(name = "updatedAt", description = "最后更新时间")
    private Date updateTime;

    @TableLogic(value = "NULL", delval = "CURRENT_TIMESTAMP")
    private Date deletedAt;
}
